﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace HotelResSystem2
{
    public class ChaseCreditAdapter : CreditInstitutionAdapter
    {
        public static string ADAPTER_NAME = "ChaseCreditAdapter";

        public override bool AuthorizePayment(int creditInfo) 
        {
            bool userFound = CheckForUser(creditInfo);
            if (userFound)
                return true;
            else
                return false; 
        }

        public override bool CheckForUser(int creditInfo)
        {
            bool found = false;
            XmlReader reader = XmlReader.Create(Properties.Settings.Default.XMLFolder + "/Chase.xml");
            string creditInfoStr = "";
            int tempCreditInfo = -1;

            while (reader.Read())
            {
                // Only detect start elements.
                if (reader.IsStartElement())
                {
                    if (reader.Name == "Customer")
                    {
                        reader.Read();
                        // skip name for now
                        reader.ReadElementString("CustomerName");
                        creditInfoStr = reader.ReadElementString("CreditInfo");
                        tempCreditInfo = Convert.ToInt32(creditInfoStr);
                        if (tempCreditInfo == creditInfo)
                        {
                            found = true;
                            break;
                        }
                    }
                }

            }
            reader.Close();

            return found;
        }
    }
}
